{include file="public/header"}
<style>
    #des{
        position: relative;
        z-index: 0;
    }
</style>
<form class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 20px 20px 0;">
    <input type="hidden" value="{$info['id']}" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-block">
            <input value="{$info['name']}" type="text" name="name" placeholder="请输入商品名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品类型</label>
        <div class="layui-input-block">
            <select name="type">
                <option value="1" {if $info.type == 1}selected{/if}>级差1</option>
                <option value="2" {if $info.type == 2}selected{/if}>级差2</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">市场价</label>
        <div class="layui-input-block">
            <input value="{$info['market_amount_format']}" type="text" name="market_amount" placeholder="请输入商品市场价" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">普通用户价格</label>
        <div class="layui-input-block">
            <input value="{$info['sale_amount_format']}" type="text" name="sale_amount" placeholder="请输入商品普通用户价格" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">会员价格</label>
        <div class="layui-input-block">
            <input value="{$info['sale_amount1_format']}" type="text" name="sale_amount1" placeholder="请输入商品会员价格" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">县代价格</label>
        <div class="layui-input-block">
            <input value="{$info['sale_amount2_format']}" type="text" name="sale_amount2" placeholder="请输入商品县代价格" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">市代价格</label>
        <div class="layui-input-block">
            <input value="{$info['sale_amount3_format']}" type="text" name="sale_amount3" placeholder="请输入商品市代价格" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">省代价格</label>
        <div class="layui-input-block">
            <input value="{$info['sale_amount4_format']}" type="text" name="sale_amount4" placeholder="请输入商品省代价格" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">合伙人价格</label>
        <div class="layui-input-block">
            <input value="{$info['sale_amount5_format']}" type="text" name="sale_amount5" placeholder="请输入商品合伙人价格" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">轮播图</label>
        <div class="layui-upload">
            <button type="button" class="layui-btn" id="imagesBtn" data-id="{$info['id']}">选择图片</button>
            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px; margin-left: 110px;">
                预览图：
                <div class="layui-upload-list" id="imagesDiv">
                    {if condition="$info.images != null"}
                    {volist name="$info.images_format" id="v" key="k"}
                    <img src="{$v}" class="layui-upload-img" height="80">
                    {/volist}
                    {/if}
                </div>
            </blockquote>
            <div class="layui-input-block">
                <input type="hidden" name="images" id="images" value="">
                <p id="imagesText"></p >
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">详情图</label>
        <div class="layui-upload">
            <button type="button" class="layui-btn" id="contentBtn" data-id="{$info['id']}">选择图片</button>
            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px; margin-left: 110px;">
                预览图：
                <div class="layui-upload-list" id="contentDiv">
                    {if condition="$info.content != null"}
                    {volist name="$info.content_format" id="v" key="k"}
                    <img src="{$v}" class="layui-upload-img" height="80">
                    {/volist}
                    {/if}
                </div>
            </blockquote>
            <div class="layui-input-block">
                <input type="hidden" name="content" id="content" value="">
                <p id="contentText"></p >
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input value="{$info['sort']}" type="text" name="sort" placeholder="请输入排序" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
    </div>
</form>

<script src="__ADMIN__/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">
    window.HOST_TYPE='2'
</script>
<script>
    layui.config({
        base: '__ADMIN__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['form', 'upload'], function(){
        var $ = layui.$
            ,form = layui.form
            ,upload = layui.upload;

        upload.render({
            elem: '#coverBtn'
            ,url: '/api/app/upload_by_id'
            ,data: {folder: 'merchant', id: $('#coverBtn').attr('data-id') + ''}
            ,accept: 'images'
            ,done: function(res) {
                console.log(res);
                //上传完毕回调
                $('#cover').val(res.data.val); //将图片路径保存到表单中
                $('.coverImage').attr('src', res.data.src); //预览图片
                $('#coverText').html('上传成功');
                layer.msg(res.msg, {icon: 1});
            },
            error: function() {
                //请求异常回调
                layer.msg('上传失败', {icon: 2});
            }
        });

        var arr = <?php echo $images_parse; ?>;
        upload.render({
            elem: '#imagesBtn'
            ,url: '/api/app/uploads/by_id'
            ,data: {folder: 'goods/{$id}/images', id: $('#imagesBtn').attr('data-id') + ''}
            ,accept: 'images'
            ,multiple: true
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                if(arr.length == 0){
                    $('#imagesDiv').html('');
                }

                obj.preview(function(index, file, result){
                    $('#imagesDiv').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img" height="80">')
                });
            }
            ,allDone: function(obj){ //当文件全部被提交后，才触发
                // console.log(obj.total); //得到总文件数
                // console.log(obj.successful); //请求成功的文件数
                // console.log(obj.aborted); //请求失败的文件数
            }
            ,done: function(res, index, upload){ //每个文件提交一次触发一次。详见“请求成功的回调”
                console.log(res);
                if(res.state == true){
                    arr.push(res.data.val);
                    $('#images').val(JSON.stringify(arr));
                    // if($('#images').val() == ''){
                    //
                    //     $('#images').val('"' + res.data.val + '"');
                    // }else{
                    //     $('#images').val($('#images').val() + ',"' + res.data.val + '"');
                    // }
                }
                console.log($('#images').val());
            }
        });

        var contentArr = <?php echo $content_parse; ?>;
        upload.render({
            elem: '#contentBtn'
            ,url: '/api/app/uploads/by_id'
            ,data: {folder: 'goods/{$id}/content', id: $('#contentBtn').attr('data-id') + ''}
            // ,url: '/api/app/upload_by_id'
            // ,data: {folder: 'merchant/product/{$id}/content', id: $('#contentBtn').attr('data-id') + ''}
            ,accept: 'images'
            ,multiple: true
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                if(contentArr.length == 0){
                    $('#contentDiv').html('');
                }
                obj.preview(function(index, file, result){
                    $('#contentDiv').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img" height="80">')
                });
            }
            ,allDone: function(obj){ //当文件全部被提交后，才触发
                // console.log(obj.total); //得到总文件数
                // console.log(obj.successful); //请求成功的文件数
                // console.log(obj.aborted); //请求失败的文件数
            }
            ,done: function(res, index, upload){ //每个文件提交一次触发一次。详见“请求成功的回调”
                console.log(res);
                if(res.state == true){
                    contentArr.push(res.data.val);
                    $('#content').val(JSON.stringify(contentArr));
                }
                console.log($('#content').val());
            }
        });
    })
</script>
{include file="public/footer"}